import { request } from '@/utils/request'
import { BASE_URL } from '@/utils/constants'
import type { MenuTree, Menu } from './types'

const MenuAPI = {
    getMenuTree(): Promise<MenuTree> {
        return request.get(`${BASE_URL}/menu`)
    },
    getFlatMenu(): Promise<Omit<Menu, 'children'>[]> {
        return request.get(`${BASE_URL}/menu/flat`)
    },
    createMenu(data: Omit<Menu, 'id' | 'children'>): Promise<Menu> {
        return request.post(`${BASE_URL}/menu`, data)
    },
    getMenuDetail(id: number): Promise<Omit<Menu, 'children'>> {
        return request.get(`${BASE_URL}/menu/${id}`)
    },
    updateMenu(id: number, data: Partial<Omit<Menu, 'children'>>): Promise<Menu> {
        return request.put(`${BASE_URL}/menu/${id}`, data)
    },
    getMenuPermission(): Promise<Omit<Menu, 'children'>[]> {
        return request.get(`${BASE_URL}/menu/permission`)
    },
    deleteMenu(id: number): Promise<void> {
        return request.delete(`${BASE_URL}/menu/${id}`)
    }
}

export default MenuAPI